package com.rolerealm.common.constant;

import lombok.Getter;

/**
 * 统一错误码枚举
 * 根据业务模块分类定义错误码
 * 
 * @author RoleRealm Team
 * @version 1.0.0
 */
@Getter
public enum ErrorCode {

    // ==================== 通用错误码 (1000-1999) ====================
    SUCCESS(200, "操作成功"),
    SYSTEM_ERROR(1000, "系统内部错误"),
    PARAM_ERROR(1001, "参数错误"),
    PARAM_MISSING(1002, "参数缺失"),
    PARAM_INVALID(1003, "参数无效"),
    REQUEST_METHOD_NOT_SUPPORTED(1004, "请求方法不支持"),
    REQUEST_MEDIA_TYPE_NOT_SUPPORTED(1005, "请求媒体类型不支持"),
    UNAUTHORIZED(1006, "未授权访问"),
    FORBIDDEN(1007, "禁止访问"),
    NOT_FOUND(1008, "资源不存在"),
    CONFLICT(1009, "资源冲突"),
    TOO_MANY_REQUESTS(1010, "请求过于频繁"),
    SERVICE_UNAVAILABLE(1011, "服务不可用"),
    TIMEOUT(1012, "请求超时"),

    // ==================== 用户管理模块错误码 (2000-2999) ====================
    USER_NOT_FOUND(2000, "用户不存在"),
    USER_ALREADY_EXISTS(2001, "用户已存在"),
    USER_REGISTER_FAILED(2002, "用户注册失败"),
    USER_LOGIN_FAILED(2003, "用户登录失败"),
    USER_LOGOUT_FAILED(2004, "用户登出失败"),
    USER_PASSWORD_ERROR(2005, "密码错误"),
    USER_ACCOUNT_DISABLED(2006, "用户账户已禁用"),
    USER_ACCOUNT_LOCKED(2007, "用户账户已锁定"),
    USER_ACCOUNT_EXPIRED(2008, "用户账户已过期"),
    USER_CREDENTIALS_EXPIRED(2009, "用户凭证已过期"),
    USER_EMAIL_NOT_VERIFIED(2010, "用户邮箱未验证"),
    USER_PHONE_NOT_VERIFIED(2011, "用户手机号未验证"),
    USER_PROFILE_UPDATE_FAILED(2012, "用户资料更新失败"),
    USER_PREFERENCE_UPDATE_FAILED(2013, "用户偏好设置更新失败"),
    USER_FAVORITE_ADD_FAILED(2014, "添加收藏失败"),
    USER_FAVORITE_REMOVE_FAILED(2015, "移除收藏失败"),
    USER_FAVORITE_NOT_FOUND(2016, "收藏不存在"),
    USER_TOKEN_INVALID(2017, "用户令牌无效"),
    USER_TOKEN_EXPIRED(2018, "用户令牌已过期"),
    USER_REFRESH_TOKEN_INVALID(2019, "刷新令牌无效"),

    // ==================== 角色管理模块错误码 (3000-3999) ====================
    CHARACTER_NOT_FOUND(3000, "角色不存在"),
    CHARACTER_ALREADY_EXISTS(3001, "角色已存在"),
    CHARACTER_CREATE_FAILED(3002, "角色创建失败"),
    CHARACTER_UPDATE_FAILED(3003, "角色更新失败"),
    CHARACTER_DELETE_FAILED(3004, "角色删除失败"),
    CHARACTER_CATEGORY_NOT_FOUND(3005, "角色分类不存在"),
    CHARACTER_TAG_NOT_FOUND(3006, "角色标签不存在"),
    CHARACTER_SEARCH_FAILED(3007, "角色搜索失败"),
    CHARACTER_RECOMMENDATION_FAILED(3008, "角色推荐失败"),
    CHARACTER_PRESET_NOT_FOUND(3009, "预设角色不存在"),
    CHARACTER_IMAGE_UPLOAD_FAILED(3010, "角色图片上传失败"),
    CHARACTER_VOICE_UPLOAD_FAILED(3011, "角色语音上传失败"),
    CHARACTER_BACKGROUND_INVALID(3012, "角色背景信息无效"),
    CHARACTER_PERSONALITY_INVALID(3013, "角色性格特征无效"),
    CHARACTER_NAME_DUPLICATE(3014, "角色名称重复"),
    CHARACTER_DESCRIPTION_TOO_LONG(3015, "角色描述过长"),

    // ==================== AI对话引擎模块错误码 (4000-4999) ====================
    AI_SERVICE_UNAVAILABLE(4000, "AI服务不可用"),
    AI_MODEL_NOT_FOUND(4001, "AI模型不存在"),
    AI_MODEL_LOAD_FAILED(4002, "AI模型加载失败"),
    AI_INFERENCE_FAILED(4003, "AI推理失败"),
    AI_RESPONSE_TIMEOUT(4004, "AI响应超时"),
    AI_RESPONSE_INVALID(4005, "AI响应无效"),
    AI_QUOTA_EXCEEDED(4006, "AI配额已超限"),
    AI_RATE_LIMIT_EXCEEDED(4007, "AI请求频率超限"),
    AI_AUTHENTICATION_FAILED(4008, "AI服务认证失败"),
    AI_AUTHORIZATION_FAILED(4009, "AI服务授权失败"),
    STT_SERVICE_FAILED(4010, "语音识别服务失败"),
    STT_AUDIO_FORMAT_INVALID(4011, "音频格式无效"),
    STT_AUDIO_TOO_LONG(4012, "音频时长过长"),
    STT_AUDIO_TOO_SHORT(4013, "音频时长过短"),
    STT_AUDIO_QUALITY_POOR(4014, "音频质量过差"),
    TTS_SERVICE_FAILED(4015, "语音合成服务失败"),
    TTS_TEXT_TOO_LONG(4016, "合成文本过长"),
    TTS_VOICE_NOT_FOUND(4017, "语音模型不存在"),
    TTS_SPEECH_RATE_INVALID(4018, "语速参数无效"),
    TTS_VOICE_TONE_INVALID(4019, "音色参数无效"),

    // ==================== 技能系统模块错误码 (5000-5999) ====================
    SKILL_NOT_FOUND(5000, "技能不存在"),
    SKILL_NOT_AVAILABLE(5001, "技能不可用"),
    SKILL_EXECUTION_FAILED(5002, "技能执行失败"),
    SKILL_TIMEOUT(5003, "技能执行超时"),
    KNOWLEDGE_QA_FAILED(5004, "知识问答失败"),
    KNOWLEDGE_QUESTION_INVALID(5005, "问题格式无效"),
    KNOWLEDGE_ANSWER_NOT_FOUND(5006, "未找到相关答案"),
    LANGUAGE_TEACHING_FAILED(5007, "语言教学失败"),
    LANGUAGE_LEVEL_INVALID(5008, "语言水平参数无效"),
    LANGUAGE_LESSON_NOT_FOUND(5009, "语言课程不存在"),
    CREATIVE_INTERACTION_FAILED(5010, "创意互动失败"),
    CREATIVE_TASK_INVALID(5011, "创意任务无效"),
    CREATIVE_RESULT_GENERATION_FAILED(5012, "创意结果生成失败"),

    // ==================== 对话历史模块错误码 (6000-6999) ====================
    CONVERSATION_NOT_FOUND(6000, "对话记录不存在"),
    CONVERSATION_CREATE_FAILED(6001, "对话记录创建失败"),
    CONVERSATION_UPDATE_FAILED(6002, "对话记录更新失败"),
    CONVERSATION_DELETE_FAILED(6003, "对话记录删除失败"),
    CONVERSATION_QUERY_FAILED(6004, "对话记录查询失败"),
    CONVERSATION_EXPORT_FAILED(6005, "对话记录导出失败"),
    CONVERSATION_IMPORT_FAILED(6006, "对话记录导入失败"),
    CONVERSATION_BACKUP_FAILED(6007, "对话记录备份失败"),
    CONVERSATION_RESTORE_FAILED(6008, "对话记录恢复失败"),
    CONVERSATION_ARCHIVE_FAILED(6009, "对话记录归档失败"),
    CONVERSATION_SEARCH_FAILED(6010, "对话记录搜索失败"),
    CONVERSATION_STATISTICS_FAILED(6011, "对话统计失败"),

    // ==================== 文件管理模块错误码 (7000-7999) ====================
    FILE_NOT_FOUND(7000, "文件不存在"),
    FILE_UPLOAD_FAILED(7001, "文件上传失败"),
    FILE_DOWNLOAD_FAILED(7002, "文件下载失败"),
    FILE_DELETE_FAILED(7003, "文件删除失败"),
    FILE_SIZE_EXCEEDED(7004, "文件大小超限"),
    FILE_FORMAT_NOT_SUPPORTED(7005, "文件格式不支持"),
    FILE_CORRUPTED(7006, "文件已损坏"),
    FILE_PERMISSION_DENIED(7007, "文件权限不足"),
    FILE_STORAGE_FULL(7008, "文件存储空间不足"),
    FILE_PROCESSING_FAILED(7009, "文件处理失败"),

    // ==================== 第三方服务模块错误码 (8000-8999) ====================
    THIRD_PARTY_SERVICE_UNAVAILABLE(8000, "第三方服务不可用"),
    THIRD_PARTY_API_ERROR(8001, "第三方API错误"),
    THIRD_PARTY_AUTH_FAILED(8002, "第三方认证失败"),
    THIRD_PARTY_QUOTA_EXCEEDED(8003, "第三方配额超限"),
    THIRD_PARTY_RATE_LIMIT_EXCEEDED(8004, "第三方请求频率超限"),
    THIRD_PARTY_TIMEOUT(8005, "第三方服务超时"),
    THIRD_PARTY_RESPONSE_INVALID(8006, "第三方响应无效"),
    EMAIL_SERVICE_FAILED(8007, "邮件服务失败"),
    SMS_SERVICE_FAILED(8008, "短信服务失败"),
    PAYMENT_SERVICE_FAILED(8009, "支付服务失败"),
    NOTIFICATION_SERVICE_FAILED(8010, "通知服务失败");

    /**
     * 错误码
     * -- GETTER --
     *  获取错误码
     *
     * @return 错误码

     */
    private final int code;

    /**
     * 错误消息
     * -- GETTER --
     *  获取错误消息
     *
     * @return 错误消息

     */
    private final String message;

    /**
     * 构造方法
     * 
     * @param code 错误码
     * @param message 错误消息
     */
    ErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据错误码获取错误枚举
     * 
     * @param code 错误码
     * @return 错误枚举
     */
    public static ErrorCode getByCode(int code) {
        for (ErrorCode errorCode : values()) {
            if (errorCode.getCode() == code) {
                return errorCode;
            }
        }
        return SYSTEM_ERROR;
    }

    @Override
    public String toString() {
        return "ErrorCode{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }
}
